package dashboard.controllers;

import javax.servlet.http.HttpServletRequest;

import com.bj58.groupbuy.action.model.User;
import com.bj58.groupbuy.action.util.SomePublicUtil;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.BeatContext.Model;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;

import dashboard.cache.ServiceBeanFactory;
import dashboard.constant.EnumCate;
import dashboard.constant.IncomeCityConst;
import dashboard.databll.PriviledgeBLL;
import dashboard.datasource.AbstractBaseService;
import dashboard.dbentity.IncomeCity;
import dashboard.utils.MyServletRequestUtils;

@Path("/income")
public class IncomeController extends MvcController {
	private SomePublicUtil spu = new SomePublicUtil();
	private AbstractBaseService<IncomeCity> imCityService = ServiceBeanFactory.get(IncomeCity.class,null);
	
	/**
	 * 收入看板-城市
	 * @return
	 * @author zhaoxiang 2015-04-30
	 */
	@Path({"/citycate"})
//	@Check("dashboard/income/trend")
	@GET
	@POST
	public ActionResult dashboard() {
		EnumCate cateEnum = null;
		try {
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			//目前的最大日期
//			String maxDate = imCityService.getMaxDate();

			Model model = beat.getModel();
			model.add("businessName", businessName);
			model.add("businessList",businessOpers);
			model.add("business_CN_Map",EnumCate.business_CN_Map);
			if(!EnumCate.total.equals(cateEnum)){
				model.add("businessName_CN", cateEnum.getDBName());
			}
			model.add("zhixiaoCityList",IncomeCityConst.ZX_CityList);
			model.add("cityCmp_citys","北京,上海");
			model.add("consume_city_indexs","xhzq,chongzhi");
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("income/cityCate");
	}
	
	
	/**
	 * 收入看板-测试页
	 * @return
	 * @author zhaoxiang 2015-05-20
	 */
	@Path({"/test"})
	@GET
	@POST
	public ActionResult test() {
		EnumCate cateEnum = null;
		try {
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			//目前的最大日期
//			String maxDate = imCityService.getMaxDate();
			
			Model model = beat.getModel();
			model.add("businessName", businessName);
			model.add("businessList",businessOpers);
			model.add("business_CN_Map",EnumCate.business_CN_Map);
			if(!EnumCate.total.equals(cateEnum)){
				model.add("businessName_CN", cateEnum.getDBName());
			}
			model.add("zhixiaoCityList",IncomeCityConst.ZX_CityList);
			model.add("cityCmp_citys","北京,上海");
			model.add("consume_city_indexs","xhzq,chongzhi");
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("income/income_test");
	}
	
	
}
